package ecustom.common.util;

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

public class Base64Util {

	public static String encodeStr(String str) {
		if (str == null || "".equals(str)) return "";
		return encode(ByteUtil.toBytes(str));
	}

	public static String encode(byte[] data) {
		if (data == null) {
			return "";
		}
		return String.valueOf(Base64.encode(data));
	}

	public static byte[] decode(String str) {
		if (str == null || "".equals(str)) {
			return null;
		}
		char[] ch = str.toCharArray();
		return Base64.decode(String.valueOf(ch));
	}

	public static String decodeStr(String str) {
		return new String(decode(str));
	}
}
